<template>
    <div>
        <div class="login_top clearfix">
            <a href="index.html" class="login_logo"><img src="/static/images/logo02.png"></a>
        </div>

        <div class="login_form_bg" id='app'>
            <div class="login_form_wrap clearfix">
                <div class="login_banner fl"></div>
                <div class="slogan fl">商品美 · 种类多 · 欢迎光临</div>
                <div class="login_form fr">
                    <div class="login_title clearfix">
                        <a href="javascript:;" class="cur">账户登录</a>
                    </div>
                    <div class="form_con">
                        <div class="form_input cur">
                            <form id="login-form" @submit.prevent="login">
                                <input type="text" v-model="username" name="" class="name_input"
                                    placeholder="请输入用户名/手机号/邮箱">
                                <div v-show="error_username" class="user_error" v-cloak>请填写用户名或手机号</div>
                                <input type="password" v-model="password" name="pwd" @keydown.enter="login" class="pass_input"
                                    placeholder="请输入密码">
                                <!-- <div v-show="error_pwd" class="pwd_error" v-cloak>{{ error_pwd_message }}</div> -->
                                <div class="more_input clearfix">
                                    <input type="checkbox" v-model="remember">
                                    <label>记住登录</label>
                                    <a href="/find_password">忘记密码</a>
                                </div>
                                <input type="submit" name="" value="登 录" class="input_submit">
                            </form>
                        </div>
                    </div>
                    <div class="third_party">
                        <a  class="qq_login">QQ</a>
                        <a href="#" class="weixin_login">微信</a>
                        <a :href="weibo_url" class="weibo_login">新浪微博</a>
                        <a href="/register" class="register_btn">立即注册</a>
                    </div>

                </div>
            </div>
        </div>

        <myfooder></myfooder>
    </div>
</template>

<script>
import axios from 'axios'
import myfooder from '../components/Fooder'
export default {
    components: {
        'myfooder': myfooder
    },
    data() {
        return {
            username: '',
            password: '',
            remember: '1',
            base_url: 'http://127.0.0.1:8000',
            // 错误提示
            error_username: false,
            weibo_url: 'https://api.weibo.com/oauth2/authorize?client_id=1923644635&redirect_uri=http://127.0.0.1:8080/callback'
        }
    },
    methods: {
        // 登录
        login() {
            // 1、实例化表单
            let form_data = new FormData()
            // 2、添加数据
            form_data.append('username', this.username)
            form_data.append('password', this.password)
            // 3、发送数据
            axios({
                url: this.base_url + '/app01/login/',
                method: 'post',
                data: form_data
            }).then(res => {
                console.log(res.data)
                if(res.data.code == 200) {
                    localStorage.setItem('token', res.data.token)
                        localStorage.setItem('username', res.data.username)
                    // 判断有没有重定向
                    if(this.$route.query.redirect) {
                        
                        // 跳转到重定向页面
                        console.log('1111111')
                        this.$router.push(this.$route.query.redirect)
                        return
                    }else{
                        
                        // 没有重定向,跳转到首页
                        console.log('22222')
                        this.$router.push({
                            name: 'Index'
                        })
                        
                    }
                }else{
                    this.error_username = true
                    this.username = ''
                    this.password = ''
                }
                

            })
        }
    },
    created() {
        console.log(this.$route.query)
    }
}
</script>

<style scoped>

</style>
